// 云函数入口文件
const cloud = require('wx-server-sdk')

cloud.init()

// 云函数入口函数
exports.main = async(event, context) => {
  let {
    type,
    imgUrl
  } = event
  switch (type) {
    case 'shenfenzheng':
      {
        // 识别身份证
        return shenfenzheng(imgUrl)
      }
    default:
      {
        return
      }
  }
}

//识别身份证
async function shenfenzheng(imgUrl) {
  try {
    const result = await cloud.openapi.ocr.idcard({
      type: 'photo',
      imgUrl: imgUrl
    })
    return result
  } catch (err) {
    console.log(err)
    return err
  }
}